package sparrowGui
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	
	import sparrowGui.impl.IScrollBar;
	import sparrowGui.utils.PubFun;
	
	public class HScrollBar2 extends HScrollBar implements IScrollBar
	{
		public function HScrollBar2(argSkin:Sprite=null)
		{
			super(argSkin);
		}
		
		override protected function init():void
		{
			if(skin && skin.parent){
				var tmparent:DisplayObjectContainer = skin.parent;
				var id:int = skin.parent.getChildIndex(skin);
				style.height = skin.height;
				style.width = skin.width;
				this.x = skin.x;
				this.y = skin.y;
				skin.x = skin.y = 0;
				tmparent.addChildAt(this,id);
				
				PubFun.changeSP2Item(slider);
				PubFun.changeSP2Item(leftBtn);
				PubFun.changeSP2Item(rightBtn);
			}
			addChild(skin);
			setSliderParams(slider.width,skinbg.width);
		}
		
		override public function setSliderParams(min:Number, max:Number, stepValue:Number=0):void
		{
			if(min>=max){
				enabled = false;
				delEvt();
				return;
			}
			enabled = true;
			skinbg.width = max;
			slider.width = min;
			
			if(!stepValue) segment = scrollDist/25;
			else segment = (sliderDist-max)*stepValue;
			addEvt();
			this.visible = true;
		}
	}
}